package viewControllers;

import graphics.GraphicalObject;

import java.util.ArrayList;

import javax.media.opengl.GL;

import physics.GameObject;

public class ViewController extends GraphicalObject{

	protected GameObject object;
	protected ArrayList<AnimationPart> parts = new ArrayList<AnimationPart>();
	protected Animator animator = null;
	protected GraphicalObject jp = new GraphicalObject();
	
	public ViewController(GameObject object){
		this.object = object;
		this.position = object.getPosition();
		this.addObject(jp);
	}
	
	public void setAnimator(Animator animator){
		this.animator = animator;
	}
	
	@Override
	public void prerender(GL gl) {
		play();
		super.prerender(gl);
		
	}

	public void play(){
		if (animator != null)
			animator.play();
	}
	
	public void stop(){
		animator.stop();
	}
		
	public void addPart(AnimationPart part){
		parts.add(part);
//		this.addObject(part);
		jp.addObject(part);
	}

	public void removePart(AnimationPart part){
		parts.remove(part);
		//this.removeObject(part);
		jp.removeObject(part);
	}

	public void initialize(){
		for (AnimationPart part : parts){
			part.initialize();
		}
	}
}
